﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HsTec.Mobile.Green.SqlServerDAL;
using Baimasoft.Manage.SqlServerDAL;

public partial class Study_StudyManage : Baimasoft.Web.UI.PageManagerTop
{
    Study MyStudy = new Study();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.BindControlEvent();
        this.HiddenID.Value = "";
        if (!this.IsPostBack)
        {
            try
            {
                AspNetHelper.IndexPageLoad(this, this.Indicator); //导航
                AspNetHelper.BtnGrantInfo(this);  //按钮控制   注意前后加载顺序: 先加载导航,后加载按钮控制; 页面加载顺序是从上向下加载的
            }
            catch
            {
            }

            this.SDT.Text = DateTime.Now.ToString("yyyy-MM") + "-01";
            this.EDT.Text = DateTime.Now.ToString("yyyy-MM-dd");

            TypeDataBind();
            GridView1.Attributes.Add("BorderColor", "LightSkyBlue");
            this.BindGridViewData();//绑定GridView,为删除服务
        }
    }

    protected override void BindGridViewData()
    {
        this.DataSource = MyStudy .GetManageInfos (GetSearchString());

        this.DataSource.DefaultView.Sort = this.SortString;
        GridView1.DataSource = this.DataSource.DefaultView;
        GridView1.DataBind();

    }

    protected void TypeDataBind()
    {
        ddlType.DataSource = MyStudy.GetTypeInfos("");
        ddlType.DataBind();
        ddlType.Items.Insert(0, "全部类别");
        ddlType.Items[0].Value = "0";
    }

    protected void Btn_3_ServerClick(object sender, EventArgs e)
    {
        try
        {
            string ids = "", sFileNameCol = "";

            System.Web.UI.HtmlControls.HtmlInputCheckBox check;

            foreach (GridViewRow row in GridView1.Rows)
            {
                check = (System.Web.UI.HtmlControls.HtmlInputCheckBox)row.FindControl("check");
                if (check.Checked)
                {
                    ids += check.Value + ",";

                    GridViewRow selectedRow = GridView1.Rows[row.RowIndex];

                    TableCell contactFE = selectedRow.Cells[1];  //Name
                    sFileNameCol += contactFE.Text.ToString().Trim();
                }
            }

            ids = ids.TrimEnd(',').ToString().Trim();

            int iback = MyStudy.DeleteInfos(ids);
            if (iback < 1)
            {
                Baimasoft.Web.UI.Message.AlertMsg(this, "没有可删除的数据!");
                return;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除成功!');location.href='StudyManage.aspx';</script>");
                return;
            }
        }
        catch
        {
            Baimasoft.Web.UI.Message.AlertMsg(this, "删除失败!");
        }
    }


    protected override string GetSearchString()
    {
        string searchStr = "(1=1)";

        if (this.ddlType .SelectedValue.ToString().Trim() != "0")
        {
            searchStr += " and a.TypeID = " + this.ddlType.SelectedValue.ToString().Trim() + "";
        }

        if (this.txtTitle.Text.Trim().Length > 0)
        {
            searchStr += " and  a.title like '%" + this.txtTitle.Text + "%' ";
        }

        if (this.SDT.Text.ToString().Trim() != "")
        {
            searchStr += " and convert(varchar(10),a.CreatDt,120) >= '" + this.SDT.Text.ToString().Trim() + "' ";
        }
        else
        {
            searchStr += " and convert(varchar(10),a.CreatDt,120) >= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' ";
        }
        if (this.EDT.Text.ToString().Trim() != "")
        {
            searchStr += " and convert(varchar(10),a.CreatDt,120) <= '" + this.EDT.Text.ToString().Trim() + "' ";
        }
        else
        {
            searchStr += " and convert(varchar(10),a.CreatDt,120) <= '" + DateTime.Now.ToString("yyyy-MM-dd") + "' ";
        }


        return searchStr;
    }

}




